package view.component.tip
{
	import core.Language;
	
	import flash.filters.DropShadowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.Dictionary;
	
	import framework.view.components.Component;
	import framework.view.components.tip.ITip;
	
	import utils.PropertyUtil;
	
	import values.avatar.AvatarTypeValue;
	import values.avatar.AvatarTypeValueList;
	import values.item.EquipmentItemTemplateValue;
	import values.item.EquipmentItemValue;
	import values.item.ItemValue;
	import values.item.NumbericItemValue;
	
	import view.component.cost.CostGroupItemProxy;
	
	public class EqumentTip extends Component implements ITip
	{
		public function EqumentTip()
		{
			super();
		}
		
		override protected function get proxyMapping():Array
		{
			return [{skin:"costObject" , classRef:CostGroupItemProxy , id:"costObject"}];
		}
		
		private function get costObject():CostGroupItemProxy
		{
			return proxys["costObject"];
		}
		
		private static const PRONAME_FILTER:DropShadowFilter = new DropShadowFilter(0 , 0 , 0x8E490B , 1.0 , 2 , 2, 20 );
		
		override protected function get skinReference():String
		{
			return "swf.ui.EqumentTipSkin";
		}
		
		private var vo:EquipmentItemValue;
		
		public function get data():*
		{
			return vo;
		}
		
		public function set data(value:*):void
		{
			vo = value;
			
			skin.hadOwnerMc.label.text = Language.getText("@had_owner_equiment");
			skin.hadOwnerMc.visible = vo.owner ? true : false;
			skin.itemNameTF.text = vo.name;
			skin.itemNameTF.textColor = (vo.template as EquipmentItemTemplateValue ).color;
			skin.forgingTF.text = "秘银" + vo.level + "级";
			
			var properties:Dictionary = PropertyUtil.initPropertyMapping(vo);
			var __y:Number = 0;
			for each (var obj:Object in properties)
			{
				var val:Number = vo[obj.prop];
				if (val == 0)
				{
					continue;
				}
				
				var proNameTxt:TextField = new TextField();
				proNameTxt.textColor = 0xECD7B3;
				proNameTxt.filters = [PRONAME_FILTER];
				proNameTxt.text = Language.getText("@property_" + obj.prop + "_name");
				skin.textHolder.addChild(proNameTxt);
				proNameTxt.y = __y;
				proNameTxt.width = proNameTxt.textWidth + 4;
				proNameTxt.height = proNameTxt.textHeight + 4;
				
				var valTxt:TextField = new TextField();
				valTxt.textColor = 0xffffff;
				valTxt.text = ( val > 0 ? "+" : "-" ) + val.toString();
				skin.textHolder.addChild(valTxt);
				valTxt.y = __y;
				valTxt.width = valTxt.textWidth + 4;
				valTxt.height = valTxt.textHeight + 4;
				valTxt.x = 75;
				__y += 18;
			}
			
			skin.txtBg.height = skin.textHolder.height + 14;
			
			skin.requirLevelConstTF.text = Language.getText("@requir_level_label");
			skin.requestLevelTF.text = (vo.template as EquipmentItemTemplateValue ).requireLevel;
			
			skin.requirLevelConstTF.y = skin.requestLevelTF.y = skin.txtBg.height + skin.txtBg.y + 5;
			
			skin.requirTypeConstTF.text = Language.getText("@requir_type_label");
			var typeStr:String = "";
			for each(var tv:AvatarTypeValue in AvatarTypeValueList.avatarTypes)
			{
				if(tv.canSupportEquip(vo.equipType))
				{
					if(typeStr != "")
					{
						typeStr += "\n";
					}
					typeStr += tv.name;
				}
			}
			
			skin.requestTypeTF.text = typeStr;
			skin.requestTypeTF.height = skin.requestTypeTF.textHeight + 4;
			
			skin.requirTypeConstTF.y = skin.requestTypeTF.y = skin.requirLevelConstTF.y + skin.requirLevelConstTF.height + 5;
			
			skin.sellConstTF.text = Language.getText("@sell_price_name") + ":";
			
			costObject.skinContent["label"].textColor = 0xffffff;
			
			costObject.data = ItemValue.createResource("coin" , 300);
			
			skin.sellConstTF.y = costObject.y = skin.requestTypeTF.y + skin.requestTypeTF.height + 20;
			
			skin.bg.height = skin.height + 6;
		}
	}
}